import { createStore } from 'vuex'

export default createStore({
  state: {
    locale: ''
  },
  mutations: {
    setLanguage(state, payload) {
      state.locale = payload.value;
      window.localStorage.setItem('locale', payload.value);
    },
    changeLanguage(state, language) {
      state.locale = language
    }
  },
  actions: {
    getLanguage(context) {
      const language = window.localStorage.getItem('locale') || 'zh-CN';
      context.commit('changeLanguage', language)
    }
  },
})
